home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: delta / whiteline CD Series - delta.iso / tex / style / misc / tabls.sty < prev    next >
Text File  |  1995-11-25  |  10KB  |  224 lines

  1. %
  2. %  T A B L S . S T Y           (ver 3.1)
  3. %
  4. %  Copyright (c) 1989, 1990, 1991, 1992  by Donald Arseneau
  5. %  from
  6. %  LaTeX, Copyright (c) 1985... by Leslie Lamport
  7. %
  8. %  Modify LaTeX's array and tabular environments to keep text from touching
  9. %  other text or hlines above or below.  See instructions after \endinput.
  10. %
  11. %----------------------------------------------------------------------
  12.  
  13. %  create registers and default settings:
  14.  
  15. \newdimen\tablinesep   \tablinesep= 1pt    \let\tablineskip=\tablinesep
  16. \newdimen\arraylinesep \arraylinesep= 1pt  \let\arraylineskip=\arraylinesep
  17. \newdimen\extrarulesep \extrarulesep= 3pt
  18.  
  19. \newdimen\@arstdepth \newdimen\@arstheight \newdimen\@skip@bove
  20.  
  21. \let\@tarlinesep\z@ % so outermost arrays will not act nested
  22.  
  23. % Change the initializations to create a smaller strut and include
  24. % my macros in the initialization for the preamble.
  25.  
  26. \def\@array[#1]#2{%  remember global variables to allow recursion
  27.  \edef\@unrecurse{\global\@skip@bove\the\@skip@bove
  28.      \global\@arstheight\the\@arstheight\global\@arstdepth\the\@arstdepth}%
  29. %  Make the strut on the first line be shorter by the linesep outside
  30.  \let\@otarlinesep\@tarlinesep \global\@skip@bove-\@otarlinesep
  31. %  This setup works for both tabular and array because of this test:
  32.  \ifx\@classz\@arrayclassz \let\@tarlinesep\arraylinesep
  33.  \else \let\@tarlinesep\tablinesep \fi
  34.  \divide\@tarlinesep\tw@% half sep is applied to height & depth
  35.  \let\@seesize\relax \let\@rememsize\relax \@mkpream{#2}%
  36.  \@tempdima\arraystretch\ht\strutbox \@tempdimb\arraystretch\dp\strutbox
  37.  \ifdim\@tarlinesep>\z@
  38.    \def\@rememsize{\protect\@r@m@msize}\let\@seesize\@s@@size
  39.    \advance\@tempdima-\@tarlinesep \advance\@tempdimb-\@tarlinesep
  40.  \fi \setbox\@arstrutbox\hbox{% set up smaller strut
  41.     \vrule \@height\@tempdima \@depth\@tempdimb \@width\z@}%
  42.  \edef\@preamble{\halign \noexpand\@halignto \bgroup
  43.  \tabskip\z@skip \unhcopy\@arstrutbox \@preamble \tabskip\z@skip &\@sharp \cr}%
  44. % I have added an extra column (&\@sharp) to take the smart strut.
  45.  \let\@startpbox\@@startpbox \let\@endpbox\@@endpbox
  46.  \if#1t\vtop \else \if#1b\vbox \else \vcenter \fi\fi
  47.  \bgroup \let\par\relax
  48.  \global\@arstheight\ht\@arstrutbox \global\@arstdepth\dp\@arstrutbox
  49.  \advance\extrarulesep.5\arrayrulewidth
  50.  \let\@sharp##\let\protect\relax \lineskip\z@skip \baselineskip\z@skip
  51.  \@preamble}
  52.  
  53. %  Change the meaning of \\ to do the final strut calculation and
  54. %  put in the smart strut
  55.  
  56. \def\@xtabularcr{\@ifnextchar[{\@argtabularcr}{\@argtabularcr[\z@]}}
  57.  
  58. \def\@xarraycr{\aftergroup\@argarraycr\@xtabularcr}
  59.  
  60. \def\@argarraycr{${}}% put this "aftergroup" so we can combine macro streams
  61.  
  62. % sense a following \hline, \cline or \end, and adjust spacing accordingly
  63.  
  64. \def\@argtabularcr[#1]{\@ifnextchar\hline
  65.    {\@mystrutcr\extrarulesep[#1]}% Note: \@tempc is next char from \@ifnextchar
  66.    {\ifx\@tempc\cline \@mystrutcr\extrarulesep[#1]\else
  67.        \ifx\@tempc\end \@mystrutcr-\@otarlinesep[#1]\else % reduce last strut
  68.           \@mystrutcr\z@[#1]\fi\fi}}
  69.  
  70. \def\@mystrutcr#1[#2]{\ifnum0=`{\fi}&\omit % end group, new column
  71.   \advance\@arstheight\@skip@bove
  72.   \ifdim#2>\z@ \advance\@arstdepth#2\fi \advance\@arstdepth#1%
  73.   \advance\@arstheight\@tarlinesep \advance\@arstdepth\@tarlinesep
  74.   \vrule \@height\@arstheight \@depth\@arstdepth \@width\z@
  75.   \global\@arstheight\ht\@arstrutbox \global\@arstdepth\dp\@arstrutbox
  76.   \global\@skip@bove\z@ \cr
  77.   \ifdim#2<\z@ \noalign{\vskip#2}\fi}
  78.  
  79. \let\@xargarraycr\@undefined   \let\@yargarraycr\@undefined % save memory
  80.  
  81. % Simulate \crcr at the end of the table, assuming that we are not in
  82. % vmode once a line of entries has started.  This fails to put in a smart
  83. % strut if the table ends without \\ while in vmode in a column entry.
  84. % Use \@unrecurse to simulate grouping of global parameters.
  85. % For nested tables and arrays, the final strut is reduced by the linesep
  86. % that will be added at the outer level.
  87.  
  88. \def\endtabular{\ifvmode\csname crcr\endcsname % just \crcr if \\ given...
  89.   \else {\ifnum0=`}\fi\@mystrutcr-\@otarlinesep[\z@]% or simulate \\ when absent
  90.   \fi\egroup\@unrecurse\egroup $\egroup}
  91.  
  92. \expandafter\let\csname endtabular*\endcsname=\endtabular
  93.  
  94. \def\endarray{\ifvmode\csname crcr\endcsname % like endtabular
  95.   \else ${\ifnum0=`}\fi\aftergroup\@argarraycr\@mystrutcr-\@otarlinesep[\z@]%
  96.   \fi\egroup\@unrecurse\egroup}
  97.  
  98. % Put \@seesize...\@rememsize in all preamble templates
  99.  
  100. \def\@tabclassz{\ifcase \@lastchclass \@acolampacol \or \@ampacol \or
  101.    \or \or \@addamp \or
  102.    \@acolampacol \or \@firstampfalse \@acol \fi
  103. \edef\@preamble{\@preamble{%
  104.   \ifcase
  105.      \@chnum \hfil\@seesize\ignorespaces\@sharp\unskip\@rememsize \hfil
  106.      \or \@seesize\ignorespaces\@sharp\unskip\@rememsize \hfil
  107.      \or \hfil\hskip\z@skip\@seesize\ignorespaces\@sharp\unskip\@rememsize
  108.   \fi}}}
  109.  
  110. \def\@arrayclassz{\ifcase \@lastchclass \@acolampacol \or \@ampacol \or
  111.    \or \or \@addamp \or
  112.    \@acolampacol \or \@firstampfalse \@acol \fi
  113. \edef\@preamble{\@preamble
  114.   \ifcase \@chnum
  115.      \hfil\@seesize $\relax\@sharp$\@rememsize \hfil
  116.       \or \@seesize $\relax\@sharp$\@rememsize \hfil
  117.       \or \hfil\@seesize $\relax\@sharp$\@rememsize \fi}}
  118.  
  119. \def\@classv{\@addtopreamble{\@seesize\@startpbox{\@nextchar}%
  120.   \ignorespaces\@sharp\@endpbox\@rememsize}}
  121.  
  122. % my macros to keep track of the size of entries.
  123.  
  124. \def\@s@@size{\setbox\z@\hbox\bgroup}
  125.  
  126. \def\@r@m@msize{\egroup % end the \hbox
  127. \edef\ahtwas{\the\@arstheight/\the\@arstdepth}%
  128.     \ifdim\ht\z@>\@arstheight \global\@arstheight\ht\z@ \fi
  129.     \ifdim\dp\z@>\@arstdepth  \global\@arstdepth \dp\z@ \fi
  130.     \unhbox\z@}
  131.  
  132. % Redefine \hline to remove notches and to give extrarulesep and
  133. % optional [] skip
  134.  
  135. \def\hline{\noalign{\ifnum0=`}\fi\kern-.5\arrayrulewidth
  136.    \hrule \@height \arrayrulewidth \kern-.5\arrayrulewidth
  137.    \futurelet\@tempa\@xhline}
  138.  
  139. \def\@xhline{\global\@skip@bove\extrarulesep
  140.       \ifx\@tempa\hline\vskip \doublerulesep\else
  141.       \ifx\@tempa[\aftergroup\@yhline\fi\fi
  142.       \ifnum0=`{\fi}}
  143.  
  144. \def\@yhline[#1]{\noalign{\global\advance\@skip@bove#1}}
  145.  
  146. % make \cline give the \extrarulesep below
  147.  
  148. \def\cline#1{\noalign{\global\@skip@bove\extrarulesep}\@cline[#1]}
  149.  
  150. \endinput
  151. % -----------------------------------------------------------------
  152. %
  153. %  Modify LaTeX's array and tabular environments to keep text from touching
  154. %  other text or hlines above or below.  There are three new parameters:
  155. %
  156. %  \tablinesep (or \tablelineskip): minimum space between text on successive
  157. %                  lines in a tabular environment.  Negative distances are
  158. %                  treated as zero.  The default value is 1pt.  0pt turns off
  159. %                  checking for touching text.  Text given in an @{ }
  160. %                  specification is never checked for overlap.
  161. %
  162. %  \arraylinesep (or \arraylineskip): like \tablinesep, but for arrays.
  163. %
  164. %  \extrarulesep : extra space to add above and below each \hline and \cline.
  165. %                  There will be at least \extrarulesep + 0.5\tablinesep
  166. %                  between an \hline and a line of text.  Negative values can
  167. %                  be used, but only until some text touches the line.
  168. %                  The default value is 3pt.
  169. %
  170. %  To limit interline separations in tables but not arrays, declare
  171. %        \setlength\arraylinesep{0pt}
  172. %  The appearance of normal LaTeX tables can be had with
  173. %        \setlength\tablinesep{0pt}
  174. %        \setlength\arraylinesep{0pt}
  175. %        \setlength\extrarulesep{0pt}
  176. %  but it would be better to not use tabls in this situation.
  177. %
  178. %  \hline[dimen]:
  179. %
  180. %  \hline has been changed to take an optional length argument just like \\
  181. %  giving the space to insert below.  This space is in addition to the
  182. %  \extrarulesep and linesep.  A negative value will reduce the space until
  183. %  the hline touches some text below, and then will have no further effect.
  184. %  E.g., \hline[-9in] draws a horizontal line while suppressing the extrarulesep
  185. %  beneath.  Also, the new \hline FIXES THE NOTCHES that used to appear at the
  186. %  junction between horizontal and vertical lines.
  187. %
  188. %  How it works:
  189. %  There are no struts in the preamble entries (lie), rather, there are
  190. %  tests to measure the maximum height and depth of all entries on a line.
  191. %  The maximum values start at the size of LaTeX's \@arstrut minus the
  192. %  appropriate linesep.  At the \\, a strut is inserted (in its own
  193. %  column) which is that maximum size plus the linesep plus any additional
  194. %  space for separation from \hline s.
  195. %
  196. %  The Downside:
  197. %  Building a table will be slower than before because the entries have to
  198. %  be boxed twice (by \@seesize and by \halign itself) instead of just once.
  199. %  \setlength\tablinesep{0pt} will recover most of this speed, with
  200. %  \extrarulesep still partially in effect--extra space will still be added
  201. %  around hlines, but it may be taken up by very tall or very deep table
  202. %  entries; thus text may still touch the lines.  Because of the speed penalty,
  203. %  it is probably best to omit the TABLS option until producing a final copy.
  204. %
  205. %  (2.2) \endtabular* is defined (it was left out before. oops!)
  206. %  change some \z@ to \z@skip. Thanks to Michael Downes.
  207. %  Create alias \tablinesep = \tablelineskip for consistency with
  208. %  \tabcolsep nomenclature. \def\\{\crcr} used in ver 2.1 didn't work right,
  209. %  so use \csname crcr\endcsname.
  210. %
  211. %  (3.0) Arrays are included! The very top and bottom struts of nested
  212. %  arrays are reduced by the lesser of the inner and outer lineseps so space
  213. %  doesn't accumulate with each level of nesting.
  214. %
  215. %  (3.1) Add some braces to match some updates to LaTeX.
  216. %
  217. %  Send problem reports to asnd@triumfcl.bitnet or asnd@Jack.TRIUMF.CA
  218. %
  219. %  Test integrity of file:
  220. %  brackets: round, square, curly, angle:   () [] {} <>
  221. %  backslash, slash, vertical, at, dollar, and: \ / | @ $ &
  222. %  hat, grave, acute (apostrophe), quote, tilde:   ^ ` ' " ~
  223.  
  224.